import { Inject, Post, Body, Get, Query } from '@midwayjs/core';
import { 
  CoolController, 
  BaseController,
  CoolUrlTag,
  TagTypes,
  CoolTag 
} from '@cool-midway/core';
import { QrcodeQrcodeEntity } from '../../entity/qrcode';
import { QrcodeQrcodeService } from '../../service/qrcode';
import { UserInfoEntity } from '../../../user/entity/info';

/**
 * 二维码信息
 */
@CoolUrlTag()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: QrcodeQrcodeEntity,
  service: QrcodeQrcodeService,
  pageQueryOp: {
    keyWordLikeFields: ['a.code'],
    fieldEq: ['a.userId', 'a.channelId', 'a.status', 'a.type'],
    select: ['a.*', 'b.nickName'],
    join: [
      {
        entity: UserInfoEntity,
        alias: 'b',
        condition: 'a.userId = b.id',
        type: 'leftJoin',
      },
    ],
  },
})
export class AppQrcodeQrcodeController extends BaseController {
  @Inject()
  qrcodeQrcodeService: QrcodeQrcodeService;

  // 根据id获取二维码信息
  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Get('/getQRCodeInfo')
  async getQRCodeInfo(@Query() body) {
    const { id } = body;
    const result = await this.qrcodeQrcodeService.getQRCodeInfo(id);
    return this.ok(result);
  }

  // 添加行为数据
  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/addBehaveLog')
  async addBehaveLog(@Body() body) {
    const result = await this.qrcodeQrcodeService.addBehaveLog(body);
    return this.ok(result);
  }
}
